using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace DungeonOfDespair
{
    public class Spell
        : Entity
    {
        private Spells m_spells;
        private Sprite m_sprite;
        private bool m_bFriendly;
        private int m_iDamage;
        private EntityDirection m_entityDirection;

        public Spell(Spells spells, Image image, bool bFriendly, int iDamage,
            EntityDirection entityDirection)
        {
            m_spells = spells;
            m_sprite = new Sprite(image);
            Bounds = new RectangleF(
                -image.Height / 4, -image.Height / 4,
                image.Height / 2, image.Height / 2);
            m_sprite.CentreHotspot(ClipPosition.Middle);
            m_bFriendly = bFriendly;
            m_iDamage = iDamage;
            m_entityDirection = entityDirection;
            m_bActive = true;
        }

        public override void Update()
        {
            base.Update();
            switch (m_entityDirection)
            {
                case EntityDirection.Left: X -= 16; break;
                case EntityDirection.Right: X += 16; break;
                case EntityDirection.Up: Y -= 16; break;
                case EntityDirection.Down: Y += 16; break;
            }

            Rectangle rectWalls = m_spells.Room.Walls;
            if (X < rectWalls.Left && m_entityDirection == EntityDirection.Left)
                m_bActive = false;
            if (X > rectWalls.Right && m_entityDirection == EntityDirection.Right)
                m_bActive = false;
            if (Y < rectWalls.Top && m_entityDirection == EntityDirection.Up)
                m_bActive = false;
            if (Y > rectWalls.Bottom && m_entityDirection == EntityDirection.Down)
                m_bActive = false;
        }

        public override void Draw(Graphics graphics)
        {
            m_sprite.ResetShape();
            switch (m_entityDirection)
            {
                case EntityDirection.Left: m_sprite.Rotate((float)Math.PI); break;
                case EntityDirection.Right: break;
                case EntityDirection.Up: m_sprite.Rotate((float) (Math.PI * -0.5f)); break;
                case EntityDirection.Down: m_sprite.Rotate((float) (Math.PI * 0.5f)); break;
            }
            m_sprite.X = X;
            m_sprite.Y = Y;
            m_sprite.Draw(graphics);
        }

        public Spells Spells
        {
            get { return m_spells; }
        }

        public bool Friendly
        {
            get { return m_bFriendly; }
            set { m_bFriendly = value; }
        }

        public int Damage
        {
            get { return m_iDamage; }
            set { m_iDamage = value; }
        }
    }
}
